<template>
  <div :class="['app-container', { 'sidebar-open': showMenu }]">
    <main-header @toggle-menu="toggleMenu"></main-header>
    <main class="page">
      <router-view></router-view>
    </main>
    <main-sidebar @hide-menu="toggleMenu(false)"></main-sidebar>
    <main-footer></main-footer>
  </div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import MainHeader from '@/components/Header.vue'
import MainSidebar from '@/components/Sidebar.vue'
import MainFooter from '@/components/Footer.vue'
import { mapMutations } from 'vuex'
export default defineComponent({
  data () {
    return {
      showMenu: false
    }
  },
  components: {
    MainHeader,
    MainSidebar,
    MainFooter
  },
  watch: {
    $route (route) {
      const matchedRoutes = route.matched
      this.setTopRouteName(matchedRoutes[0].name)
      matchedRoutes[1] ? this.setSecondRouteName(matchedRoutes[1].name) : this.setThirdRouteName('')
      matchedRoutes[2] ? this.setThirdRouteName(matchedRoutes[2].name) : this.setThirdRouteName('')
    }
  },
  methods: {
    ...mapMutations('layout', ['setTopRouteName', 'setSecondRouteName', 'setThirdRouteName']),
    toggleMenu (flag: boolean) {
      this.showMenu = flag === undefined ? !this.showMenu : flag
    }
  }
})
</script>
<style lang="scss">
body,html {
  padding: 0;
  margin: 0;
  background-color: #fff
}

body {
  font-family: Inter,Roboto,Oxygen,Fira Sans,Helvetica Neue,sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 16px;
  color: #303133;
}
#app {
  max-width: 100%;
}
ul {
  list-style-type: none;
}
h1,h2,h3,h4,h5,h6 {
    font-weight: 500;
    margin: 0;
}
a {
  text-decoration: none;
  color: #303133;
}
.page {
  margin-left: 350px;
  max-width: 1200px;
  padding-top: 55px;
  padding-bottom: 20px;
}
@media (max-width: 719px) {
  .page {
    margin-left: 0;
  }
}

</style>
